module MC.View {
    export class Index {
        public constructor() {
            this.init();
        }

        private init() {
            MC.apiC('/api/home/index', {}, (json: any) => {
                //	 console.log(json);
                $('.jobs_ul').html('');
                $('.fac_ul').html('');
                jobs_ul('.jobs_ul', json.jobs);
                fac_ul('.fac_ul', json.factorys);
                this.lunbotu(json.lunbotu);
            });

            MC.user.Load(() => {
                if (MC.user.isLogin) {
                    if (MC.user.info.is_company != 0 || MC.user.info.is_factory != 0) {
                        $('#homeFabu').show();
                    }
                }
            });
        }

        private swiper:any=null;
        private lunbotu(list: any) {
            if(!list){
                return;
            }
            if(this.swiper){
                this.swiper.destroy();
            }
            $('#homePpt .swiper-container .swiper-wrapper').html('');
            for (let i = 0; i < list.length; i++) {
                let one = list[i];
                let html = `<div class="swiper-slide">
                  <a href="` + one.link + `" class="line">
                      <img class="pic" src="` + one.img + `"/>
                  </a>
              </div>`;
                $('#homePpt .swiper-container .swiper-wrapper').append(html);
            }
            this.swiper = new Swiper('.swiper-container', {
                pagination: {
                    el: '.swiper-pagination',
                },
            });
        }


    }

    /** 生成工厂html代码 */
    export function fac_ul(jselect: string, list: any) {
        let jq = $(jselect);
        for (let i = 0; i < list.length; i++) {
            let obj = list[i];
            let tablist = ``;
            if (obj.out_type) {
                for (let i = 0; i < obj.out_type.length; i++) {
                    tablist += `<a class="tabone">` + obj.out_type[i] + `</a>`;
                }
            }
            //
            let li = `<li class="jobli">
                    <div class="jcon">
                        <a class="jobli_a" href="/h5/index/facShow.html?uid=` + obj.uid + `">
                            <div class="top clearfix">
                                <span class="jobName">` + obj.facType + `</span>
                                <span class="emolument">` + obj.com_city + `</span>
                            </div>
                        </a>
                        <p class="desc skill">` + obj.detail + `</p>
                        <div class="tablist clearfix">
							` + tablist + `
                        </div>
                        <a class="jobli_a" href="/h5/index/facShow.html?uid=` + obj.uid + `">
                            <div class="userinfo clearfix">
                                <div class="headdiv">
                                    <img src="` + obj.head + `"
                                         class="head" />
                                </div>
                                <div class="usernameDiv">
                                    <span class="company_name">` + obj.comName + `</span>
                                    <span class="uname">` + obj.uname + `</span>
                                </div>

                            </div>
                        </a>
                    </div>
                </li>`;
            jq.append(li);
        }
    }

    /** 生成岗位html代码 */
    export function jobs_ul(jselect: string, list: any) {
        let jq = $(jselect);
        for (let i = 0; i < list.length; i++) {
            let obj = list[i];
            let li = `<li class="jobli">
                    <div class="jcon">
                        <a class="jobli_a" href="/h5/index/job/jobShow.html?jobId=` + obj.id + `"><div class="top clearfix">
                            <span class="jobName">` + obj.jobName + `</span>
                            <span class="emolument">` + obj.emolument + `</span>
                        </div></a> 
                        <div class="tablist">
                            <a class="skill tabone">` + obj.address + `</a>
                            <a class="tabone">` + obj.education + `</a>
							<a class="tabone">年龄` + MC.API.tihuan(obj.age_range, ',', '-') + `</a>
                        </div>
                         <a class="jobli_a" href="/h5/index/job/jobShow.html?jobId=` + obj.id + `">
                         <span class="company_name">` + obj.company_name + `</span>
						 <div class="userinfo clearfix">
						     
                            <div class="headdiv">
                              
                                <img src="` + obj.head + `"
                                     class="head" />
                            </div>
                            <div class="usernameDiv">
                              
                                <span class="uname">` + obj.uname + `</span>
                            </div>

                        </div>
						</a>
                    </div>
                </li>`;
            jq.append(li);
        }
    }
}